package com.clear.honghefinance.biz.modules.system.member.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.clear.honghefinance.biz.modules.system.member.domain.entity.MemberBindWxOpenId;
import com.clear.honghefinance.biz.modules.system.member.mapper.MemberBindWxOpenidMapper;
import com.clear.honghefinance.biz.modules.system.member.service.IMemberBindWxOpenidService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表绑定微信openid表 服务实现类
 * </p>
 *
 * @author 程序员clear
 * @since 2024-08-07
 */
@Service
@Slf4j
public class MemberBindWxOpenidServiceImpl extends ServiceImpl<MemberBindWxOpenidMapper, MemberBindWxOpenId> implements IMemberBindWxOpenidService {

    /**
     * 根据appId和openId查询
     *
     * @param appId  appId
     * @param openId openId 用户唯一标识
     * @return MemberBindWxOpenid实体
     */
    @Override
    public MemberBindWxOpenId get(String appId, String openId) {
        return this.getOne(Wrappers.<MemberBindWxOpenId>lambdaQuery()
                .eq(MemberBindWxOpenId::getAppId, appId)
                .eq(MemberBindWxOpenId::getOpenId, openId));
    }

    /**
     * 绑定appId、openId、memberId的关系
     *
     * @param appId
     * @param openId
     * @param memberId
     */
    @Override
    public boolean register(String appId, String openId, long memberId) {
        MemberBindWxOpenId memberBindWxOpenid = new MemberBindWxOpenId();
        memberBindWxOpenid.setAppId(appId);
        memberBindWxOpenid.setOpenId(openId);
        memberBindWxOpenid.setMemberId(memberId);
        memberBindWxOpenid.initDefault();
        return this.save(memberBindWxOpenid);
    }
}
